package com.idis.managerApp;

import com.spring4all.swagger.EnableSwagger2Doc;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

import javax.servlet.MultipartConfigElement;
import java.io.File;

@SpringBootApplication(scanBasePackages = {"com.idis.service","com.idis.managerApp"},exclude = {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@EnableSwagger2Doc
public class ManagerAppApplication {

	public static void main(String[] args) {
		SpringApplication.run(ManagerAppApplication.class, args);
	}

	@Value("${ip}")
	String ip;

	@Value("${port}")
	String port;

	@Bean
	public String DBUrl(){
		return "http://"+ip+":"+port;
	}

	@Bean
	MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		String location = System.getProperty("user.dir") + "/manager/tmp";
		File tmpFile = new File(location);
		if (!tmpFile.exists()) {
			tmpFile.mkdirs();
		}
		factory.setLocation(location);
		return factory.createMultipartConfig();
	}

	@Bean
	public org.springframework.web.client.RestTemplate restTemplate(RestTemplateBuilder builder) {
		return builder.build();
	}
}
